<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once APPLICATION_PATH.'/misc/additional.php';
require_once APPLICATION_PATH.'/misc/sessionController.php';
class Application_Controllers_Admin_ActionPasswordController
{   public $wrongMessage="";
    //validation before registration
    public function prePassword($username,$form){
        $admin=new Application_Model_DbTable_Admin();
        $validatorChain = new Zend_Validate();
        $validatorChain->addValidator(
                         new Zend_Validate_StringLength(array('min' => 6,
                         'max' => 16)))
                         ->addValidator(new Zend_Validate_Alnum());
        //Validation's logic begin here

        //check username is it between 6 and 20 chars?

        if(!$admin->checkLogin($username, $form->getValue('password'))){
            $this->wrongMessage="Password lama anda salah ";
            return false;
        }
        if(!$validatorChain->isValid($form->getValue('newpassword'))){
            //action
            $this->wrongMessage="username harus diantara 6 dan 16 chars";
            return false;
        }
        if($form->getValue('newpassword') != $form->getValue('repassword')){
            $this->wrongMessage="Password pada kolom password baru dan tulis ulang password baru tidak sama";
            return false;
        }
        return true;

    }
    //action on registration
    public function onPassword($id,$form){
        $sessionController = new sessionController();
        $admins = new Application_Model_DbTable_Admin();
        $admins->updateAdminPassword((int)$id, $form->getValue('newpassword'));
        $actionLog = new Application_Model_DbTable_Actionlog();
        $actionLog->addActionLog($sessionController->getSessionLogId(),
                                  "[".$_SERVER['REMOTE_ADDR'].
                                   "] Change Profile Password ".
                                   "Username :".$sessionController->getSessionUsername()." ");


    }
    public function postEdit($username,$password){

    }
}
?>
